<%@ page pageEncoding="utf-8"%> 
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="com.course.db.*"%>

<%
	String footer = (String)session.getAttribute("PageFooter");
	request.setAttribute("layout","main.jsp");
	request.setAttribute("page_title","温岭选课系统-课程申报审核");
	int i = 0;
  	List<Hashtable<String, String>> user_list = (List<Hashtable<String, String>>) session.getAttribute("UserList");
	Iterator<Hashtable<String, String>> user_it = user_list.iterator();
	String type = (String)session.getAttribute("type");
	CourseTerm courseterm = (CourseTerm)session.getAttribute("CourseTerm");
 %>
 
	<link href="css/jquery.ui.tabs.css" rel="stylesheet">
	<link href="css/jquery.ui.theme.css" rel="stylesheet">
	<link href="css/div_win.css" rel="stylesheet"> 
	<script src="js/div_win.js"></script>
	<script src="js/jquery-1.5.2.min.js"></script>
	<script src="js/jquery-ui-1.8.11.custom.min.js"></script>
	<script src="js/jquery.ui.tabs.js"></script>
	<script type="text/javascript" src="js/popup.js"></script>
	
	<script>
	
	function getArgs(strParame) {
        var args = new Object( );
        var query = location.search.substring(1);



        var pairs = query.split("&"); // Break at ampersand
        for(var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf("="); 
        if (pos == -1) continue; 
        var argname = pairs[i].substring(0,pos); 
        var value = pairs[i].substring(pos+1); 
        value = decodeURIComponent(value); 
        args[argname] = value; 
        }
        return args[strParame]; 
        }
	
	$(function() {
		$( "#tabs" ).tabs({selected:getArgs("tab")});
	});
	
	function del(userid,username){
	   $.ajax({
			url: base_path+"Admin/delUser.do",
			type: "POST",
			data: {"userid":userid},
			beforeSend: function(XMLHttpRequest){
				//alert(username);
				return confirm("确定要删除用户"+username+"吗？");
			},
			success: function(data, textStatus){
				if(data=="success"){
					alert("删除用户"+username+"成功");
				}else{ 
				
				}
			},

			complete: function(XMLHttpRequest, textStatus){
				window.location.href="../Admin/userList.do?tab=1";
			},
			error: function(){
				$("#ajaxResult").html("服务器异常，请联系网络管理员");
			}
		});
   }
	function edit(userid){
		   $.ajax({
				url: base_path+"Admin/editUser.do",
				type: "POST",
				data: {"userid":userid},
				beforeSend: function(XMLHttpRequest){
					
				},
				success: function(data, textStatus){
					if(data=="student"){
						//alert("删除用户"+username+"成功");
						ShowIframe('编辑学生信息',base_path+"admin/editStudent.jspx",500,300);
					}else if(data=="teacher"){ 
						ShowIframe('编辑教师信息',base_path+"admin/editTeacher.jspx",500,300);
					}
					else if(data == "admin")
					{
						ShowIframe('导入学生信息',base_path+"admin/loadStudent.jspx",500,300);
					}
				},

				complete: function(XMLHttpRequest, textStatus){
					//window.location.href="../Admin/userList.do?tab=1";
				},
				error: function(){
					$("#ajaxResult").html("服务器异常，请联系网络管理员");
				}
			});
	   }
	
	function adduser()
	{
		ShowIframe('新增用户',base_path+"admin/addUser.jspx",500,300);
	}
	function loadteacher()
	{
		ShowIframe('导入教师信息',base_path+"admin/loadTeacher.jspx",500,300);
	}
	function setterm()
	{
		ShowIframe('设置当前学期',base_path+"admin/setterm.jspx",500,300);
	}
	function loadstudent()
	{
		ShowIframe('导入学生信息',base_path+"admin/loadStudent.jspx",500,300);
	}
	function editpwd(userid,username)
	{
		ShowIframe('更改用户密码',base_path+"admin/editUserPwd.jspx?userid="+userid+"&username="+username,300,200);
	}
	</script>
<div style="width:100%; margin:1px;text-align:center;margin-top:5px;margin-bottom:20px;">
 	
 	<p style="border:0;font-size:14px;padding-bottom:0;text-align:center;">
 	<!-- 	<b>课程申报记录</b>
  		<select>
  			<option value="全部">全部</option>
  			<option value="2011年第一学期">2011年第一学期</option>
  			<option value="2011年第二学期">2011年第二学期</option>
  			<option value="2012年第一学期">2012年第一学期</option>
  		</select>
	 -->
	</p>
<div id="tabs" style="height:700px;width:90%;margin-left:5%;">
	<ul>
		<!-- <li><a href="#tabs-1">信息导入</a></li> -->
		<li><a href="#tabs-1">公告管理</a></li>
		<li><a href="#tabs-2">系统管理</a></li>
	</ul>
	
	<div id="tabs-1" style="width:100%;margin-left:0;padding-left:0;margin-top:20px;">
		<div style="margin-top:20px;align:left">
			当前学期：<%=courseterm.getYear() %><%=courseterm.getTerm() %>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:setterm()">[设置当前学期]</a>&nbsp;&nbsp;&nbsp;
		</div>
		<br>
		<form action="Admin/addBoard.do" method="post">
		<table  style="border:0px solid gray;align:middle;width:80%;margin-left:10%; margin-top:40px">
			<tbody>
				<tr>
					<td width=10%>标题：</td>
					<td><input size="80" type="text" name="title"/></td>
				</tr>
				<tr>
					<td>正文：</td>
					<td><textarea cols=80 rows=20 name="content" style="margin-top:5px;margin-bottom:5px;"></textarea></td>
				</tr>
				<tr><td colspan=2 align=right><input type="submit" value="提交"></td></tr>
			</tbody>
		</table>
		</form>
	</div>
	<div id="tabs-2" style="width:100%;margin-left:0;padding-left:0;margin-top:20px;">
		<div style="margin-top:20px;align:left">
			<a href="javascript:loadteacher()">[导入教师]</a>&nbsp;&nbsp;&nbsp;
			<a href="javascript:loadstudent()">[导入学生]</a>&nbsp;&nbsp;&nbsp;
			<a href="javascript:adduser()">[增加用户]</a>&nbsp;&nbsp;&nbsp;
		</div>
		<br>
 		<form action="Admin/userList.do" method="post">
	 		<table  style="border:0px solid gray;align:middle;width:60%;margin-left:20%; margin-top:40px">
	 			<tr>
	 			<td><b>查询条件</b></td>
	 			<td>用户名</td>
	 			<td><input type="text" size=10 name="username"/></td>
				<td>用户类型</td>
		  		<td>
			  		<select name="usertype" style="width:100px;">
			  			<% if(type!=null && type.trim().equalsIgnoreCase("全部")){%>
 							<option value="全部" selected>全部</option>
	 					<% }else {%>
	 						<option value="全部">全部</option>
	 					<% }if(type!=null && type.trim().equalsIgnoreCase("student")){%>
	 						<option value="student" selected>学生</option>
	 					<% }else {%>
	 						<option value="student">学生</option>
	 					<% }if(type!=null && type.trim().equalsIgnoreCase("teacher")){%>
	 						<option value="teacher" selected>教师</option>
	 					<% }else {%>
	 						<option value="teacher">教师</option>
	 					<%} if(type!=null && type.trim().equalsIgnoreCase("admin")){%>
	 						<option value="admin" selected>管理员</option>
	 					<%} else {%>
	 						<option value="admin">管理员</option>
 						<%} %>
			  		</select>
		  		</td>
		  		<td><input type="submit" value="提交"></td>
		  		</tr>
		  	</table>
	  	</form>
		<table  style="border:0px solid gray;align:middle;width:80%;margin-left:10%; margin-top:40px">
			<tbody>
				<tr align="left"  bgcolor="#f0f0f0">
					<td >用户名</td>
					<td >姓名</td>
					<td >用户类型</td>
					<td >年级</td>
					<td >介绍</td>
					<td >操作</td>
				</tr>
				<%
					user_it = user_list.iterator();
		        	while(user_it.hasNext())
					{
						Hashtable<String, String> adminList_hash  = user_it.next();
				%>
				<tr>
					<td ><%=adminList_hash.get("username") %></td>
					<td ><%if(adminList_hash.get("name") !=null){%><%=adminList_hash.get("name") %><%} %></td>
					<td ><%=adminList_hash.get("type") %></td>
					<td ><%if(adminList_hash.get("grade") !=null){%><%=adminList_hash.get("grade") %><%} %></td>
					<td ><%if(adminList_hash.get("introduction") !=null){%><%=adminList_hash.get("introduction") %><%} %></td>
					<td >
					<%if(!adminList_hash.get("type").equals("admin")) {%>
						<a href="javascript:edit('<%=adminList_hash.get("user_id")%>')" class="approve" >编辑</a> &nbsp;|&nbsp;
					<%} %>
						<a href="javascript:del('<%=adminList_hash.get("user_id")%>','<%=adminList_hash.get("username")%>')" class="approve" >删除</a> &nbsp;|&nbsp;
						<a href="javascript:editpwd('<%=adminList_hash.get("user_id")%>','<%=adminList_hash.get("username")%>')" class="approve" >修改密码</a> &nbsp;
					</td>
				</tr>
				<%} %>
			</tbody>
		</table>
		<br>
		<%
			if(footer!=null)
    			out.println(footer);
     	%>
	</div>
	</div>
</div>
